package com.itheima.health.controller;

import com.itheima.health.common.Result;
import com.itheima.health.pojo.OrderDto;
import com.itheima.health.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author cfr
 * @date 2022/1/6
 * @TIME:20:52
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private OrderService orderService;
    @PostMapping("/submit.do")
    public Result submit(@RequestBody OrderDto orderDto){
        if(!orderDto.getValidateCode().equals(request.getSession().getAttribute(orderDto.getTelephone()))){
            return new Result(false,"验证码错误" );
        }
        Result result=orderService.submit(orderDto);
        return result;

    }
}
